﻿Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Navigation

Partial Public Class BlogItem
    Inherits Page

    Private ReadOnly _blogItemViewModel As BlogItemViewModel

    Public Sub New()
        Me.InitializeComponent()
        _blogItemViewModel = New BlogItemViewModel()
        Me.DataContext = _blogItemViewModel
    End Sub

    'Executes when the user navigates to this page.
    Protected Overrides Sub OnNavigatedTo(ByVal e As NavigationEventArgs)
        '        '获取导航到此页面的 Uri 中携带的参数
        '        Dim blogId As Long = CType(NavigationContext.QueryString("blogId"), Long)
        '        '将 blogId 传给 BlogItemViewModel，以便显示相应的博客内容
        '#Disable Warning BC42358 ' 由于此调用不会等待，因此在调用完成前将继续执行当前方法
        '        _blogItemViewModel.LoadBlog(blogId)
        '#Enable Warning BC42358 ' 由于此调用不会等待，因此在调用完成前将继续执行当前方法
        '如果用户未登录，则跳转到登录页面
        If Application.Current.Resources("UserId") Is Nothing Then
            NavigationService.Navigate(NavigationData.LOGIN_PAGE_URI)
        End If
    End Sub

    Private Sub BUT_MusicControl_Click(sender As Object, e As RoutedEventArgs)
        If _blogItemViewModel.SongPlayStatus = "无法播放" OrElse MEDIA_MusicPlayer.Source Is Nothing Then
            _blogItemViewModel.SongPlayStatus = "无法播放"
            Exit Sub
        End If
        If _blogItemViewModel.SongPlayStatus = "播放中" Then
            MEDIA_MusicPlayer.Pause()
            _blogItemViewModel.SongPlayStatus = "已暂停"
        Else
            MEDIA_MusicPlayer.Play()
            _blogItemViewModel.SongPlayStatus = "播放中"
        End If
    End Sub

End Class
